package cn.mux.jdk8;

import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

public class TestRandom {
	public static void main(String[] args) {
		Random random = new Random();
		System.out.println("random.nextboolean():"+random.nextBoolean());
		byte[] buffer = new byte[16];
		random.nextBytes(buffer);
		System.out.println(Arrays.toString(buffer));
		
		System.out.println(Math.copySign(1.2,-1.0));
		
		System.out.println(Math.signum(2.3));
		System.out.println(Math.signum(-1.3));
		
		
		/**
		 * random 种子
		 */
		
		Random r1 = new Random(50);
		System.out.println("第一个种子为50的对象");
		System.out.println(r1.nextInt());
		System.out.println(r1.nextBoolean());
		System.out.println(r1.nextFloat());
		System.out.println(r1.nextDouble());
		System.out.println("----------------");
		Random r2 = new Random(50);
		System.out.println("第2个种子为50的对象");
		System.out.println(r2.nextInt());
		System.out.println(r2.nextBoolean());
		System.out.println(r2.nextFloat());
		System.out.println(r2.nextDouble());
		System.out.println("----------------");
		Random r3= new Random(50);
		System.out.println("第3个种子为50的对象");
		System.out.println(r3.nextInt());
		System.out.println(r3.nextBoolean());
		System.out.println(r3.nextFloat());
		System.out.println(r3.nextDouble());
		System.out.println("----------------");
		
		Random rand  = new Random(System.currentTimeMillis());
		System.out.println(rand.nextInt());
		
		/**
		 * 多线程环境下 ThreadLocalRandom 
		 */
		ThreadLocalRandom localRandom = ThreadLocalRandom.current();
		System.out.println(localRandom.nextInt(4,20));
		System.out.println(localRandom.nextDouble(2.0,10.0));
	}
}
